#!/sbin/openrc-run
# Copyright 1999-2013 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2

extra_commands="reload"

FROX_CONFIG="/etc/frox.conf"
FROX_PID_FILE="/var/run/frox/frox.pid"
FROX_OPTS="-f ${FROX_CONFIG}"

checkconfig() {
	local piddir="$(dirname ${FROX_PID_FILE})"
	checkpath -q -d -o ftpproxy:ftpproxy -m 0770 "${piddir}" || return 1
	if [ ! -f "${FROX_CONFIG}" ] ; then
		eerror "missing ${FROX_CONFIG}"
		return 1
	fi
}

start() {
	checkconfig || return 1
	ebegin "Starting ${SVCNAME}"
	start-stop-daemon --start --quiet --exec /usr/sbin/frox -- ${FROX_OPTS}
	eend $?
}

stop() {
	ebegin "Stopping ${SVCNAME}"
	start-stop-daemon --stop --quiet --exec /usr/sbin/frox --pidfile "${FROX_PID_FILE}"
	eend $?
}

reload() {
	ebegin "Reloading configuration"
	start-stop-daemon --signal HUP --pidfile "${FROX_PID_FILE}"
	eend $?
}
